package com.gitee.cirnochat.notification.model.dto;

import com.github.flanchanowo.request.PushNotification;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class NotificationDTO {

    private List<String> to;

    private String title;

    private String body;

    public NotificationDTO(String title, String body) {
        this.title = title;
        this.body = body;
    }

    /**
     * 适配器方法：将NotificationDTO转换为PushNotification
     * @return {@link PushNotification}
     */
    public PushNotification toPushNotification() {
        return PushNotification.builder().to(to)
                .title(title)
                .body(body)
                .build();
    }

    /**
     * 适配器方法：将PushNotification转换为NotificationDTO
     * @param pushNotification {@link PushNotification}
     * @return {@link NotificationDTO}
     */
    public static NotificationDTO fromPushNotification(PushNotification pushNotification) {
        NotificationDTO notificationDTO = new NotificationDTO();
        notificationDTO.setTo(pushNotification.getTo());
        notificationDTO.setTitle(pushNotification.getTitle());
        notificationDTO.setBody(pushNotification.getBody());
        return notificationDTO;
    }
}
